/**
 * Copyright 2009 Adam Ruggles.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.sapien.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;

import com.google.code.sapien.dao.CategoryDAO;
import com.google.code.sapien.model.Category;
import com.google.inject.Inject;

/**
 * A JPA implementation of the {@link com.google.code.sapien.dao.CategoryDAO} interface.
 * @author Adam
 * @version $Id$
 * 
 * Created on May 6, 2009 at 11:04:39 PM 
 */
public class CategoryJpaDAO extends AbstractJpaDAO<Category> implements	CategoryDAO {
	/**
	 * Constructs a category JPA data access object.
	 * @param entityManager The entity manager.
	 */
	@Inject
	public CategoryJpaDAO(final EntityManager entityManager) {
		super(entityManager);
	}

	/**
	 * {@inheritDoc}
	 * @see com.google.code.sapien.dao.CategoryDAO#getCount()
	 */
	public int getCount() {
		return ((Number) getEntityManager().createNamedQuery("category.getCount").getSingleResult()).intValue();
	}

	/**
	 * {@inheritDoc}
	 * @see com.google.code.sapien.dao.CategoryDAO#listAll()
	 */
	@SuppressWarnings("unchecked")
	public List<Category> listAll() {
		return getEntityManager().createNamedQuery("category.listAll").getResultList();
	}
}
